package io.gitee.kotle.android

import android.app.Application
import android.content.Context
import androidx.lifecycle.ProcessLifecycleOwner
import androidx.startup.Initializer
import io.gitee.kotle.android.library.crash.CrashHelper
import io.gitee.kotle.android.utils.AppBackgroundRun
import io.gitee.kotle.android.utils.MvvmActivityLifecycleCallbacksUtil

/**
 * 自动初始化
 */
class BaseLibraryInit : Initializer<Application> {
    override fun create(context: Context): Application {
        val app = context as Application
        BaseGlobalConst.internalApp = app
        //监听程序生命周期
        ProcessLifecycleOwner.get().lifecycle.addObserver(AppBackgroundRun)
        app.registerActivityLifecycleCallbacks(MvvmActivityLifecycleCallbacksUtil())
        //崩溃拦截
        CrashHelper.initCrash()
        return app
    }

    override fun dependencies(): List<Class<out Initializer<*>>> {
        return emptyList()
    }

}